package com.meihua.baoleyi.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.meihua.baoleyi.R;
import com.meihua.baoleyi.adapters.OrderFragmentAdapter;
import com.meihua.baoleyi.base.BaseActivity;
import com.meihua.baoleyi.common.APIServer;
import com.meihua.baoleyi.fragment.order.OrderFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by liming on 2017/10/17.
 * 我的订单
 */

public class MyOrderActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.text_title)
    TextView text_title;//标题
    @Bind(R.id.text_back)
    ImageView text_back;//返回
    @Bind(R.id.tabs)
    TabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;
    private List<Fragment> mFragment = new ArrayList<>();
    private OrderFragmentAdapter mAdapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);
        ButterKnife.bind(this);
        initView();
    }
    private void initView() {
        text_title.setText("我的订单");
        List<String> type = new ArrayList<>();
        type.add("全部");
        type.add("待付款");
        type.add("待发货");
        type.add("已发货");
        type.add("售后");
        mFragment.add(OrderFragment.newInstance(APIServer.ORDER_ALLORDERS,1));//全部
        mFragment.add(OrderFragment.newInstance(APIServer.ORDER_PAYMENT,2));//待付款
        mFragment.add(OrderFragment.newInstance(APIServer.ORDER_DROPSHIPPING,3));//待发货
        mFragment.add(OrderFragment.newInstance(APIServer.ORDER_SHIPPED,4));//已发货
        mFragment.add(OrderFragment.newInstance(APIServer.ORDER_AFTER,5));//售后
        mAdapter = new OrderFragmentAdapter(getSupportFragmentManager(), type, mFragment);
        viewPager.setAdapter(mAdapter);
        viewPager.setOffscreenPageLimit(4);
        tabLayout.setupWithViewPager(viewPager);
        text_back.setOnClickListener(this);
    }

    /**
     * 点击事件
     *
     * @param view
     */
    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.text_back://返回
                finish();
                break;
        }
    }
}
